package com.learn.proxy.cglib.base;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.swing.DesktopUtil;
import com.skill.test.ValidHolder;
import net.sf.cglib.core.DebuggingClassWriter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

import java.io.File;

/**
 *
 * @author XuYang
 * @since 2025/10/13 16:28
 */
public abstract class BaseProxy
    extends ValidHolder
{
    private final String directory = "E://tmp//cglib";

    protected abstract boolean open();

    @BeforeEach
    void setUp() throws Exception {
        // 生成的代理对象写入地址   默认生成在目标类同一目录中
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, directory);
        FileUtil.del(directory);
        FileUtil.mkdir(directory);
    }

    @AfterEach
    void tearDown() throws Exception {
        String openDirectory = this.getClass().getPackage().getName().replaceAll("\\.", "/");
        openDirectory = directory + "\\" + openDirectory;
        if (FileUtil.exist(openDirectory) && open()) {
            DesktopUtil.open(new File(openDirectory));
        }

    }
}
